package com.yoomiito.app.adapter.goods.list.sort

import android.text.Spannable
import android.text.SpannableString
import android.text.Spanned
import android.text.TextUtils
import android.text.style.ForegroundColorSpan
import android.text.style.RelativeSizeSpan
import android.text.style.StrikethroughSpan
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yoomiito.app.*
import com.yoomiito.app.base.App
import com.yoomiito.app.model.gift.GiftGoods
import com.yoomiito.app.utils.*
import com.yoomiito.app.widget.CouponView
import com.zhy.view.flowlayout.FlowLayout
import com.zhy.view.flowlayout.TagAdapter
import com.zhy.view.flowlayout.TagFlowLayout
import java.util.ArrayList

class ThemeYouPinGoodsAdapter(data: List<GiftGoods>?) : BaseQuickAdapter<GiftGoods, BaseViewHolder>(R.layout.item_gife_goods, data) {

    override fun convert(helper: BaseViewHolder?, item: GiftGoods?) {
        helper?.getView<ImageView>(R.id.item_gift_pic).let {
            ImageLoader.getInstance().into(mContext, item?.banner, it,R.drawable.goods_default)
        }
        helper?.setGone(R.id.goodsFlag, false)
        helper?.setText(R.id.goodsTitle, item?.product_name)

        //价格
        val priceT = item?.sale_price?.removeDecimalPoint()
//        if (!App.mAppConfig.isLogin || item?.coin!!.isEmptyOr0() || item?.yo_money_not == 0) {//优米为0不显示
//            val price = if (item?.market_price!!.isEmptyOr0()) "¥${priceT} " else "¥${priceT} ¥${item?.market_price.removeDecimalPoint()}"
//            helper?.setText(R.id.goodsPrice, price.goodsPrice(priceT!!))
//            helper?.setGone(R.id.oldGoodsPrice, false)
//        } else {
//            val s = item?.cash.removeDecimalPoint()
//            val price = "¥${s} +${item?.yo_money_not}优米"
//            helper?.setText(R.id.goodsPrice, price.youmiGoodsPrice(s))
//            helper?.setText(R.id.oldGoodsPrice, SpannableUtils.getSpannable("¥${item?.market_price.removeDecimalPoint()}", 0))
//            helper?.setGone(R.id.oldGoodsPrice, !item?.market_price.isEmptyOr0())
//        }
        if (!App.mAppConfig.isLogin) {//优米为0不显示
//            val price = if (item?.market_price!!.isEmptyOr0()) "¥${priceT} " else "¥${priceT} ¥${item?.market_price.removeDecimalPoint()}"
//            helper?.setGone(R.id.oldGoodsPrice, false)
        } else {
//            val price = "¥${priceT} 可抵扣¥${item?.deduction_account}"
//            helper?.setText(R.id.goodsPrice, price.youmiGoodsPrice(priceT!!))
//            helper?.setText(R.id.oldGoodsPrice, SpannableUtils.getSpannable("¥${item?.market_price?.removeDecimalPoint()}", 0))
//            helper?.setGone(R.id.oldGoodsPrice, !item?.market_price!!.isEmptyOr0())
        }
         helper?.setText(R.id.goodsPrice, item?.sale_price)


        //佣金
        helper?.setGone(R.id.awardView, false)
        val couponView = helper?.getView<CouponView>(R.id.couponView)
        couponView?.setHeaderText("赚")
        if (App.mAppConfig.isLogin && UserInfoConfig.getRoleId()>Type.LevelType.VIP_4) {//会员 粉丝不显示
            if (SpannableUtils.isEmptyOr0(item?.commission)) {
                couponView?.visibility = View.GONE
            } else {//粉丝以上显示奖
                couponView?.setText("¥${SpannableUtils.handlePrice(item?.commission)}")
                couponView?.visibility = View.VISIBLE
            }
        } else {
            couponView?.visibility = View.GONE
        }

        //标签
        helper?.setGone(R.id.item_gift_flowLayout, false)
        helper?.setText(R.id.goodsDesTv, item?.productPoint)
//        helper?.setGone(R.id.goodsDesTv, !item!!.product_point.isNullOrEmpty())
//        val tagFlowLayout = helper?.getView<TagFlowLayout>(R.id.item_gift_flowLayout)
//        val s = ArrayList<String>()
//        if (!TextUtils.isEmpty(item?.product_point)) {
//            s.add(item!!.product_point)
//        }
//        tagFlowLayout?.adapter = object : TagAdapter<String>(s) {
//            override fun getView(parent: FlowLayout, position: Int, o: String): View {
//                val tv = LayoutInflater.from(mContext).inflate(R.layout.item_goods_flag, parent, false) as TextView
//                val lp = tv.layoutParams as ViewGroup.MarginLayoutParams
//                lp.leftMargin = 0
//                //tv.setLayoutParams(lp);
//                tv.text = if (o.length > 8) o.substring(0, 8) + "..." else o
//                return tv
//            }
//        }

        helper?.setText(R.id.goodsSaleSize, "月销${item?.volume.toString()}")
    }

}